package com.koo.modules.store.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koo.common.utils.MyStrUtil;
import com.koo.common.utils.PageUtils;
import com.koo.common.utils.Query;
import com.koo.modules.store.dao.StoreImageDao;
import com.koo.modules.store.entity.StoreImageEntity;
import com.koo.modules.store.service.StoreImageService;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("storeImageService")
public class StoreImageServiceImpl extends ServiceImpl<StoreImageDao, StoreImageEntity> implements StoreImageService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        Object key = params.get("key");
        LambdaQueryWrapper<StoreImageEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(MyStrUtil.isNotEmpty(key), StoreImageEntity::getName, key)
                .or().like(MyStrUtil.isNotEmpty(key), StoreImageEntity::getUrl, key);

        IPage<StoreImageEntity> page = this.page(
                new Query<StoreImageEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}